<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 100 的求和
        function sums() {
            let result = 0;
            for (let i = 0; i <= 100; i++) {
                result = result + i;
            }
            console.log(result);
        }


        sums();

        // 作业：逢 7 过的函数,统计学生成绩的平均数,各种金字塔,补零案例,闰年
        //  逢 7 过的函数
        function seven() {
            for (i = 0; i < 100; i++) {
                if ((i % 7 != 0) && (i % 10 != 7) && (parseInt(i / 10) != 7)) {
                    console.log(i);
                }
            }
        }
        seven();

        //  统计学生成绩的平均数
        function result() {
            let num = prompt('请输入班级总人数');
            let sum = 0;
            for (let i = 1; i <= num; i++) {
                let score = prompt('请输入第' + i + '个学生的成绩');
                sum = sum + parseFloat(score);
            }
            num = parseInt(num);
            alert('班级总成绩为' + sum);
            alert('班级平均分为' + sum / num);
            console.log(typeof sum);

        }
        result();

        //  金字塔一号
        let sum = prompt('请输入一个数字');

        function triangle() {
            if (sum <= '6') {

                for (let i = 1; i <= sum; i++) {
                    let star = "";
                    for (let j = 1; j <= sum - i; j++) {
                        star = star + " ";
                    }
                    for (let j = 1; j <= i * 2 - 1; j++) {
                        star = star + "*";
                    }
                    console.log(star);
                }
            } else {
                for (let i = sum; i >= 1; i--) {
                    let star = "";
                    for (let j = sum - i; j >= 1; j--) {
                        star = star + " ";
                    }
                    for (let j = i * 2 - 1; j >= 1; j--) {
                        star = star + "*";
                    }
                    console.log(star);
                }
            }
        }
        triangle();
        //  金字塔二号
        function triangle2() {

            let num2 = prompt('请输入行数');
            for (let i = num2; i > 0; i--) {
                let star = '';
                for (let j = 0; j <= num2 - i; j++) {
                    star = star + '*';
                }
                console.log(star);
            }

            let num = prompt('请输入行数');
            for (let i = num; i > 0; i--) {
                let star = '';

                for (let k = 1; k < i; k++) {
                    star = star + " ";
                }
                for (let j = 0; j <= num - i; j++) {
                    star = star + '*';
                }
                console.log(star);
            }
        }
        triangle2();

        // 补零案例
        function number() {
            let num = prompt('请输入一个数');
            num = num.length < 2 ? '0' + num : num;
            console.log(num);
        }
        number();

        // 闰年
        function years() {
            let year = prompt('请输入年份');
            if ((year % 4 == 0) && (year % 100 != 0) || ((year % 100 == 0) && (year % 400 == 0))) {
                console.log(year + '年是闰年');
            } else {
                console.log(year + '年是闰年');
            }
        }
        years();
    </script>
</body>

</html>